

<template>

  <div style="width: 40%;height: 88%;background-color: whitesmoke;margin-top: 40px;margin-left: 30%">
    <p>签到记录</p>
    <div style="width:100%;height: 200px;">
      <div style="width:50%;height: 200px  ;float: left">
        <p>已签次数：{{this.user.qiandao}}</p>
      </div>
      <div style="width:50%;height: 200px;float: left;">
        <p>未签次数：{{this.weiqian}}</p>
      </div>
    </div>

    <div v-if="this.hh===true">
      <p>进行中的签到记录</p>
      <p>{{time}}</p>

      <el-button type="success"  @click="jump('SignInAtPoint')">前往签到</el-button>
    </div>
    <div v-if="this.hh===false">
      <p>没有进行中的签到记录</p>

    </div>

  </div>



</template>



<script>
  export default{
    data () {
      return {
        user:'',
        weiqian:'',
        endTime : '2019-05-10 22:15:00',
        time : '',
        flag : false,
        hh:false,

      }
    },
    mounted () {

      var user= JSON.parse(window.sessionStorage.getItem("user"));

      this.id=user.id

      axios.post('/user/findGroupByUid',{
        id:this.id,
        uid:this.id
      }).then((response) => {
        let ee=response.data
        console.log(ee)

        this.user=ee

        this.weiqian=this.user.weiqian-this.user.qiandao

        if(this.user.starttime!=null){
          this.hh=true
          var ff=this.user.starttime
          var fff=ff.split(".")
          console.log(fff[0])
          var ffff=fff[0].split("T")
          var fffff=ffff[0]+" "+ffff[1]

         // this.endTime=fffff
        }else{
          this.hh=false
        }


      }).catch((response)=>{

      })



      let time = setInterval(()=>{
        if(this.flag == true){
          clearInterval(time)
        }
        this.timeDown()
      },500)
    },
    // props : {
    //   endTime : {
    //     type : String
    //   }
    // },
    methods : {
      jump(path){
        this.$router.replace({path:path})

      },

      timeDown () {
        const endTime = new Date(this.endTime)
        const nowTime = new Date();
        let leftTime = parseInt((endTime.getTime()-nowTime.getTime())/1000)
        let d = parseInt(leftTime/(24*60*60))
        let h = this.formate(parseInt(leftTime/(60*60)%24))
        let m = this.formate(parseInt((leftTime+600)/60%60))
        let s = this.formate(parseInt(leftTime%60))
        if(leftTime <= 0){
          this.flag = true
          this.$emit('time-end')
        }
        this.time = `${h}小时${m}分${s}秒`     // 需要修改时间样式的话 ，比如需要什么30分钟倒计时，就只保留分和秒
      },
      formate (time) {
        if(time>=10){
          return time
        }else{
          return `0${time}`
        }
      }
    }
  }
</script>

<style scoped>
</style>
